package bishi.jinshanyun;

import java.util.*;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/09/15 20:41
 */
public class one {
    static int res = 0;
    static Set<Integer> seta = new HashSet<>();

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] nums = new int[N];
        for (int i = 0; i < N; i++) {
            nums[i] = sc.nextInt();
        }
        bfs(nums, 0, M, 0, 3,new ArrayList<>());
        System.out.println(res);
    }

    public static void bfs(int[] nums, int index, int M, int sum, int c, List<Integer> list) {
        Set<Integer> set = new HashSet<>();
        for (int i = index; i < nums.length; i++) {
            if (set.contains(nums[i])) continue;
            int pp = nums[i]*list.get(0)*list.get(1);
            if (c == 1&&!seta.contains(pp)) {
                if ((sum + nums[i]) % M == 0) res++;
                seta.add(pp);
            } else {
                set.add(nums[i]);
                int finalI = i;
                bfs(nums, i + 1, M, sum + nums[i], c - 1,new ArrayList<Integer>(list){{add(nums[finalI]);}});
            }
            set.add(nums[i]);
        }

    }
}
